Skip to content

feat(mcp): add debug logging mode for tool calls and errors#180

Closed
annextuckner wants to merge 1 commit into
tuckner/mcp-toolsfrom
tuckner/mcp-debug-logging
Closed

feat(mcp): add debug logging mode for tool calls and errors#180
annextuckner wants to merge 1 commit into
tuckner/mcp-toolsfrom
tuckner/mcp-debug-logging

Conversation

@annextuckner
Copy link
Copy Markdown
Contributor

What

Adds a debug logging mode that surfaces tool calls and error responses live in the terminal.

pnpm run server-http:debug     # HTTP mode + debug logging
pnpm run server-stdio:debug    # stdio mode + debug logging
# or set MCP_DEBUG=true / LOG_LEVEL=debug on the existing server-* scripts
  • lib/logger.ts — log level is now env-driven (MCP_DEBUG / LOG_LEVEL). Adds a pino-pretty stderr target. Errors surface to the terminal in normal runs; the full request/response stream shows when debug is on. The tmp log files still capture everything. stderr is safe in both modes — it is never the MCP protocol channel.
  • lib/tool-logging.ts (new) — withToolLogging() wraps registerTool once so every tool logs uniformly: args and successful responses at debug level, error responses and thrown errors always. The access token rides on extra.authInfo and is never logged.
  • lib/depscore-tool.ts — apply the wrapper in createConfiguredServer, the shared factory for both transports.
  • package.jsonserver-http:debug / server-stdio:debug scripts.

Stacked

Based on #179 (the MCP tools PR) since both edit createConfiguredServer. Retarget to main once #179 merges.

Test

  • pnpm run test:node-test — 77 tests pass
  • oxlint clean on the changed files; tsgo clean on lib/
  • Verified both modes by hand: debug mode prints tool call / tool result; normal mode prints only error responses to stderr

MCP_DEBUG=true raises the log level to debug and streams pretty logs to
stderr, surfacing each tool call's args and any error response live in
the terminal. A central registerTool wrapper logs every tool uniformly;
error responses also surface to stderr in normal runs. New server-http:debug
and server-stdio:debug scripts set the flag.
John-David Dalton (jdalton) added a commit that referenced this pull request Jun 1, 2026
Picks up #180, adapted to the current getDefaultLogger()-based logger
(the PR's pino changes are obsolete — pino was removed in the bundle
migration). lib/tool-logging.ts wraps srv.registerTool so every tool call
+ result logs via the SOCKET_DEBUG-gated debug() helper, while error
results and thrown errors always log at error level. Wired centrally in
createConfiguredServer(). Adds server-stdio:debug / server-http:debug
scripts (SOCKET_DEBUG=1). test/tool-logging.test.ts covers pass-through,
isError, and throw paths.

Co-authored-by: annextuckner <annextuckner@users.noreply.github.com>
@jdalton
Copy link
Copy Markdown
Collaborator

Landed in main as c0e39cc (feat(logging): add debug logging mode for tool calls and errors), with you credited as co-author. Adapted to current main: the pino-based logger.ts changes are obsolete (pino was removed during the bundle migration in favor of getDefaultLogger()), so the feature was re-implemented around the current logger — lib/tool-logging.ts wraps srv.registerTool to log every call/result via the SOCKET_DEBUG-gated debug() helper, while error results and thrown errors always log at error level. Wired centrally in createConfiguredServer(), with server-stdio:debug / server-http:debug scripts and a vitest test. (This depended on #179's server scaffolding, which also landed.) Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants